package com.delicious.dao.impl;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.delicious.dao.BaseDao;
import com.delicious.dao.UserDao;
import com.delicious.entity.Users;

public class UserDaoImpl extends BaseDao implements UserDao {

	public Users checkIsAdmin(String username, String password) {
		Users user = null;
		String sql = "select * from users where password = ? and username = ? and isAdmin=0";
		openConnection();
		ResultSet rs = null;
				
		try {
			rs = executeQuery(sql, new Object[]{password,username});
			if(rs.next()){
				int id = rs.getInt("id");
				Date lastLoginTime = rs.getDate("lastLoginTime");
				int isAdmin = rs.getInt("isadmin");
				user = new Users(id, username, password, lastLoginTime, isAdmin);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeConnection();
		}
		
		return user;
	}

}
